package com.mqy.spring.AOP;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author 13159 //作者
 * @version V1.0 //版本
 * @Project 2022.3.4SpringProxy
 * @Package com.mqy.spring.AOP
 * @Description:
 * @Date 2022/3/5 16:27//日期
 * @Motto:放下杂念,只为迎接明天更好的自己
 */

/*在目标之前执行*/

public class MyMethodBeforeAdvice2 implements MethodInterceptor {
    /*环绕通知*/
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("MyMethodBeforeAdvice2中的方法invoke执行了");

        System.out.println("开启事务");
        System.out.println("校验参数");
        Object proceed = null;/*执行原始方法*/
        try {
            proceed = invocation.proceed();
            System.out.println("提交事务");
            System.out.println("写入日志");
            return proceed ;
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println("发现异常--回滚");
        }
        return null ;
    }
}
